package com.xindaoapp.happypet.viewpager.windows;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.xindaoapp.happypet.R;
import com.xindaoapp.happypet.bean.Message;
import com.xindaoapp.happypet.utils.Constants;
import com.xindaoapp.happypet.viewpager.ViewPagerWindow;

/**
 * 引用好友，我的粉丝{@link MyAttentionWindow}
 * 
 * @author xindaoapp
 * 
 */
@Deprecated
public class MyFansWindow extends ViewPagerWindow {

    public MyFansWindow(Activity context) {
        super(context);
    }

    @Override
    protected View onCreateView() {
        return View.inflate(mContext, R.layout.layout_listview, null);
    }

    private PullToRefreshListView vPullToRefreshListView;
    private View vLoadingView;

    @Override
    protected void initViews() {
        super.initViews();
        vLoadingView = getView().findViewById(R.id.loading);
        vPullToRefreshListView = (PullToRefreshListView) getView().findViewById(R.id.listview);
        vPullToRefreshListView.setOnRefreshListener(mOnRefreshListener);
        vPullToRefreshListView.setOnItemClickListener(mOnItemClickListener);
    }

    private final OnItemClickListener mOnItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Message info = (Message) parent.getAdapter().getItem(position);
            Intent data = new Intent();
            data.putExtra(Constants.KEY_POST_NAME, info.subject);
            if (info.pics.size() > 0) {
                data.putExtra(Constants.KEY_POST_COVER, info.pics.get(0));
            }
            mContext.setResult(Activity.RESULT_OK, data);
            mContext.finish();
        }
    };
    private final OnRefreshListener<ListView> mOnRefreshListener =
            new OnRefreshListener<ListView>() {

                @Override
                public void onRefresh(PullToRefreshBase<ListView> refreshView) {
                    onLoadDatas();
                }
            };

    @Override
    protected void onLoadDatas() {
        // HappyPetApplication
        // .get()
        // .getMoccaApi()
        // .getFollowFans(UserState.getUserUid(), Constants.PAGE_FIRST, Constants.PAGE_SIZE,
        // new IRequest<List<Fan>>() {
        //
        // @Override
        // public void request(List<Fan> t) {
        // if (null != t) {
        // vPullToRefreshListView
        // .setAdapter(new FansAdapter(getBaseContext(), t,
        // Constants.PAGE_SIZE,
        // R.layout.menu_message_item,
        // R.layout.item_loading, true));
        // }
        // vLoadingView.setVisibility(View.GONE);
        // }
        // });
    }

}
